/**
  *@File文件:CommissionController.java
  *@Date日期:2017年7月20日 下午2:32:28
  *@Copyright版权:Corporation 2017
  */
package com.qiaomengapp.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qiaomengapp.bean.User;
import com.qiaomengapp.exception.CustomException;
import com.qiaomengapp.service.ICommissionManageService;

/**
 * @Description描述:
 * @Author作者 wangzongwen
 * @Date日期:2017年7月20日
 */
@Controller
@RequestMapping("commission/api")
public class CommissionController {

	@Autowired
	private ICommissionManageService iCommissionManageService;

	/**
	 * @Description描述: 查询佣金提现需要显示的信息
	 * @param session
	 *            域对象
	 * @return
	 * @return Object 保存数据的对象
	 */
	@RequestMapping(value = "/selectCommissionGetMessage")
	@ResponseBody
	public Object selectCommissionGetMessage(HttpSession session) {
		// 得到session中保存的用户对象
		User user = (User) session.getAttribute("user");
		if (user == null) {
			user = new User();
			user.setId(1);
		}
		// 根据用户id查询相应信息
		try {
			Object object = iCommissionManageService.selectCommissionGetMessage(user.getId());
			return object;
		} catch (CustomException e) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("error", e.getMessage());
			return map;
		}
	}

	/**
	 * @Description描述: 用户进行佣金提现
	 * @param shopId
	 *            佣金对应商铺id
	 * @param money
	 *            提现的金额
	 * @param cardCode
	 *            提现的银行卡号
	 * @param session
	 *            域对象
	 * @return
	 * @return Object 保存数据的对象
	 */
	@RequestMapping(value = "/updateGetCommission/{shopId}/{money}/{cardCode}")
	@ResponseBody
	public Object updateGetCommission(@PathVariable("shopId") int shopId, @PathVariable("money") double money,
			@PathVariable("cardCode") long cardCode, HttpSession session) {

		// 得到用户对象
		User user = (User) session.getAttribute("user");
		if (user == null) {
			user = new User();
			user.setId(1);
		}
		// 定义map集合保存信息
		Map<String, String> map = new HashMap<String, String>();
		// 进行佣金提现
		try {
			iCommissionManageService.updateGetCommission(shopId, money, user.getId(), cardCode);
			map.put("success", "提现申请成功！");
			return map;
		} catch (CustomException e) {
			map.put("error", e.getMessage());
			return map;
		}
	}

}
